<template>
    <div>
        <city-header></city-header>
        <city-search :cities='cities'></city-search>
        <city-list 
            :cities='cities' 
            :hot='hotCities'
            :letter='letter'
            >
        </city-list>
        <city-alphabet 
            :cities='cities'
            @change='handleBetterChange'  
            >
        </city-alphabet>
    </div>
</template>
<script>
// 进行ajax操作
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
export default {
    name: 'City',
    components: {
        CityHeader,
        CitySearch,
        CityList,
        CityAlphabet
    },
    data(){
        return {
            cities: {},
            hotCities: [],
            // 父组件向子组件传值
            letter: ''
        }
    },
    methods: {
        getCityInfo(){
            axios.get('/api/city.json')
                .then(this.handleGetCityInfoSucc)
        },
        // res接收mock数据的接口
        handleGetCityInfoSucc(res){
            res = res.data
            if(res.ret&&res.data){
                const data = res.data
                this.cities = data.cities
                this.hotCities = data.hotCities
            }
            console.log(res);
            
        },
        // 兄弟组件之间的传值，通过父子组件来传值，也可以通过bus来传值
        // 携带一个letter参数
        handleBetterChange(letter){
            this.letter = letter
            // console.log(letter);//获取到字母
            

        }
    },
    mounted() {
        this.getCityInfo()
    },
}
</script>

<style lang='stylus' scoped>

</style>


